//import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.DateTime;
import com.alibaba.excel.util.DateUtils;
import tool.utils.DateUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.Calendar;
import java.util.Date;

/**
 * @Author：xz
 * @Date：2023/7/20
 */
public class DateTest {
    public static void main(String[] args) throws Exception {
        test6();
    }

    public static void test7() throws ParseException {
        Date now = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date end = simpleDateFormat.parse("2024-03-11 23:59:59");
        long days = DateUtil.between(new Date(), end).toDays();
        System.out.println(days);
        int i = now.compareTo(end);
        System.out.println(i);
    }

    private static void test5() throws Exception {
//        LocalDate date = LocalDate.parse("2022/8/21");
//        System.out.println(date);
        Date overdueDay = null;
        String formatDate = null;
        try {
            overdueDay = tool.utils.DateUtil.parseDate("2022/8/32");
            formatDate = tool.utils.DateUtil.formatDate(overdueDay);
        }catch (Exception e) {
            e.printStackTrace();
            System.out.println("逾期日时间格式不正确");
        }

        System.out.println(overdueDay);
        System.out.println(formatDate);
    }


    private static void test1() {
        Date date = new Date();
        SimpleDateFormat sdf1 = new SimpleDateFormat("yy");
        SimpleDateFormat sdf2 = new SimpleDateFormat("MM");
        SimpleDateFormat sdf3 = new SimpleDateFormat("dd");
        SimpleDateFormat sdf4 = new SimpleDateFormat("yyMMdd");
        String year = sdf1.format(date);
        String month = sdf2.format(date);
        String day = sdf3.format(date);
        System.out.println(year + month + day);
        System.out.println("当前时间为：" + year + "年" + month + "月" + day + "日");
        System.out.println(sdf4.format(date));
    }

    private static void test2() {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
        String batchDate = sdf.format(date);
        // 生成编号   根据 机构前缀+批次日期 模糊查询案件批次号，若存在案件则取最新的+1，若不存在则编号为0001
//        long endTime = DateUtil.endOfDay(date).getTime();
//        long startTime = date.getTime();
//        long seconds = (long) Math.ceil((endTime - startTime) * 1.0 / 1000);
//        double hours = seconds / 60.0 / 60;
//        System.out.println(endTime);
//        System.out.println(startTime);
//        System.out.println(seconds);
//        System.out.println(hours);
    }

    private static void test3() throws ParseException {
        String dateStr = "20230701";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        Date date = sdf.parse(dateStr);
        String format = DateUtils.format(date, "yyyy-MM-dd");
        String year = format.substring(0, 4);
        String month = format.substring(5,7);
        String day = format.substring(8, 10);
        dateStr = year+"年"+month+"月"+day+"日";
        System.out.println(dateStr);
    }

    private static void test4() {
        System.out.println(cn.hutool.core.date.DateUtil.beginOfMonth(cn.hutool.core.date.DateUtil.beginOfMonth(new Date())));
        System.out.println(cn.hutool.core.date.DateUtil.endOfMonth(cn.hutool.core.date.DateUtil.beginOfMonth(new Date())));
    }

    public static void test6() {
        Date now = new Date();
        System.out.println("now："+now);

        Date dateTime = cn.hutool.core.date.DateUtil.beginOfDay(now);
        System.out.println(dateTime);
        System.out.println("dateTime："+dateTime);

        Date startDate = DateUtil.dateAdd(dateTime, 1);
        System.out.println(startDate);

        Date endDate = DateUtil.dateAdd(dateTime, 2);
        System.out.println(endDate);

        System.out.println(DateUtil.dateAdd(dateTime, 3));

    }

}
